<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>云信 Web Demo</title>
	<link rel="stylesheet" href="css/base.css"/>
	<link rel="stylesheet" href="css/animate.css"/>
	<link rel="stylesheet" href="css/index.css?v=1"/>
	<link rel="icon" href="images/icon.ico" type="image/x-icon"/>
</head>
<body>
	<div class="bad-network hide tc radius5px" id="j-errorNetwork">已与服务器断开，请检查网络连接</div>
	<div class="wrapper radius10px" id="j-wrapper">
		<div class="row tc">
			<a onclick="openIM()">
				<button type="button" class="btn btn-login" id="j-loginBtn">IM即时通讯DEMO</button>
			</a>
		</div>
		<div class="row tc">
			<a onclick="openChatroom()">
				<button type="button" class="btn btn-login" id="j-loginBtn">聊天室DEMO</button>
			</a>
		</div>
		<div id="privateEnvSwitch" class="row hide">
			<label class="row-private-env"><input type="checkbox" onchange="changeEnv()">&nbsp;&nbsp;私有化环境</label>
		</div>
		<div id="privateEnvIpt" class="row hide">
			<input class="row-private-url" type="text" onblur="changeEnvUrl()" placeholder="输入私有化环境配置文件URL">
		</div>
	</div>
	<div id="footer" class="footer tc">
		<p class="hide">为了更好地体验本Demo，建议您使用Edge、Chrome、FireFox、Safari、360等主流浏览器。</p>
		<p>&copy;1997 - 2018 网易公司版权所有</p>
	</div>
</body>
<script type="text/javascript">
	var $envBox = document.getElementById('privateEnvSwitch')
	var $envIpt = document.getElementById('privateEnvIpt')
	var $envSwitch = $envBox.querySelector('input')
	var $envUrl = $envIpt.querySelector('input')
	$envSwitch.checked = (window.localStorage.getItem('env') === 'private')
	$envUrl.value = window.localStorage.getItem('privateConfUrl') || ''
	// 如果当前可配置私有化环境则显示表单和值，否则不显示并且清除表单和值
	if (location && (location.host && /^(\d)+\.(\d)+\.(\d)+\.(\d)+/.test(location.host) || ~location.hash.indexOf('env=private') || ~location.search.indexOf('env=private'))) {
		$envBox.className = 'row'
	} else {
		$envSwitch.checked = false
	}
	changeEnv()
	function changeEnv() {
		if ($envSwitch.checked) {
			$envIpt.className = 'row'
		} else {
			$envIpt.className = 'row hide'
		}
	}
	function storageEnv() {
		if ($envSwitch.checked) {
			window.localStorage.setItem('env', 'private')
		} else {
			window.localStorage.removeItem('env')
		}
	}
	function changeEnvUrl() {
		$envUrl.value = $envUrl.value.trim()
		if ($envUrl.value && /^(http|https):\/\/(\S)+.(\S)+/.test($envUrl.value)) {
			window.localStorage.setItem('privateConfUrl', $envUrl.value)
		} else {
			window.localStorage.removeItem('privateConfUrl')
			alert('请输入正确的私有化环境配置文件URL地址')
		}
	}
	function openIM() {
		storageEnv()
		location.href = '/webdemo/im/main.html'
	}
	function openChatroom() {
		storageEnv()
		location.href = '/webdemo/im/chatroom/list.html'

	}
</script>
</html>
